package com.csw.shuanfa.SuanFa;

/**
 * 整数数组，找出子数组的最大和
 */
public class charChild {
    public static void main(String[] args) {
        int[] a = {-2, -1, -3, 4, -1, 2, 1, -5, 4};
        int sum = Integer.MIN_VALUE;
        for (int i = 1; i <= a.length; i++) {//子数组长度
            for (int m = 0; m < a.length; m++) {//数组遍历
                int temp = 0;//每次要比较的数
                for (int j = 0; j < i; j++) {//按照子数组长度在数组中移动比较
                    int c = m + j;
                    if (c >= a.length) {
                        break;
                    }
                    temp += a[c];
                }
                if (temp > sum) {
                    sum = temp;
                }

            }
        }
        //sum);
    }
}
